<template>
  <div>
    <div v-if="xuanguHasData" class="xuangu_blm" @click.capture="clickHandle">
      <jgy-render-sdk
        statName="yyzs"
        :answer="answer.content"
        sourceType="Iwencai"
        language="zh"
        :jumpFun="jgyJumpFun"
      />
         <div v-if="hasMoreData" class="page_more_link f14" @click="showMore">
        查看{{ xuanguMoreCount }}条结果
      </div>
    </div>
    <jgy-render-sdk
      v-else-if="vType === 'aigc'"
      statName="yyzs"
      :answer="answer.content"
      sourceType="Iwencai"
      language="zh"
      :jumpFun="jgyJumpFun"
    />
    <jgySdk
      v-else
      statName="yyzs"
      jgyOutStyle="{}"
      divclass="message_padding white"
      :answer="answer.content"
    ></jgySdk>

    <BlmXuanguMore
      :total="xuanguMoreCount"
      :visible="xuanguMoreVisible"
      @update:visible="xuanguMoreVisible = $event"
      :xuanguData="xuanguData"
    />
  </div>
</template>
<script>
import BlmXuanguMore from "./BlmXuanguMore.vue";
export default {
  props: {
    answer: {
      default: {},
      type: Object,
    },
  },
  data() {
    return {
      xuanguMoreVisible: false,
      xuanguData: {},
    };
  },
  components: { BlmXuanguMore },
  computed: {
    xuanguHasData() {
      const components = this.answer.content.components;
      const isXuanguTable = components.filter((item) => {
        return this.typeIsXuanguTable(item.show_type);
      });
      if (isXuanguTable.length === 0) {
        return false;
      }
      if (isXuanguTable[0].data.datas.length > 0) {
        return isXuanguTable[0].data;
      }
      return false;
    },
    vType() {
      if (
        this.answer.content.page.render_for &&
        this.answer.content.page.render_for === "aigc"
      ) {
        return "aigc";
      }

      const components = this.answer.content.components;
      const isXuanguTable = components.filter(
        (item) => item.show_type === "xuangu_tableV1"
      );
      return isXuanguTable.length > 0 ? "xuangu" : "other";
    },
    // 新增：判断是否有更多数据
    hasMoreData() {
      const components = this.answer.content.components;
      const isXuanguTable = components.filter((item) => {
        return this.typeIsXuanguTable(item.show_type);
      });
      if (isXuanguTable.length === 0) {
        return false;
      }
      return (
        isXuanguTable[0].data.meta &&
        isXuanguTable[0].data.meta.extra.has_more_data
      );
    },
    // 修改：始终返回数值类型
    xuanguMoreCount() {
      const components = this.answer.content.components;
      const isXuanguTable = components.filter((item) => {
        return this.typeIsXuanguTable(item.show_type);
      });
      if (isXuanguTable.length === 0) {
        return 0;
      }
      if (
        isXuanguTable[0].data.meta &&
        isXuanguTable[0].data.meta.extra.has_more_data
      ) {
        return isXuanguTable[0].data.meta.extra.row_count || 0;
      }
      return 0;
    },
  },
  methods: {
    typeIsXuanguTable(show_type) {
      return show_type === "jgyXuanguTable1" || show_type === "jgyTable1";
    },
    showMore() {
      this.xuanguMoreVisible = true;
      const components = this.answer.content.components;
      const isXuanguTable = components.filter((item) => {
        return this.typeIsXuanguTable(item.show_type);
      });
      this.xuanguData = isXuanguTable[0].data.meta.extra;
    },
    jgyJumpFun(e) {
      console.log(e);
    },
    clickHandle(e) {
      console.log("clickHandle", e);
      const components = this.answer.content.components;
      const isXuanguTable = components.filter((item) => {
        return this.typeIsXuanguTable(item.show_type);
      });
      window.currentSortTableDataExtra = isXuanguTable[0].data.meta.extra;
    },
  },
};
</script>
<style lang="less" scoped>
@import (once) "@/styles/variable.less";
.page_more_link {
  height: @height25;
  line-height: @height25;
  text-align: center;
  color: @primary-3;
  font-size: 12px;
  padding: @padding5 0;
}
.export-btn {
  width: @width50;
  border-radius: 4px;
  background: @primary-1;
  color: white;
  height: @height25;
}
</style>
